package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.OpenPlatformEnum;
import com.frogs.system.util.SexEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class ContactAddRequest extends Request {

	private Integer id;
	
	private String relatives;
	
	private String realName;
	
	private Integer sex;
	
	private Integer age;
	
	private String phone;
	
	private Integer userId;
	
	private Integer openPlatformId;
	
	private Integer type;
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		this.relatives = requestInfo.getParameter(ApiUrlParamEnum.relatives.getParamName(), "");
		this.sex = requestInfo.getIntParameter(ApiUrlParamEnum.sex.getParamName(), SexEnum.UNKNOW.getId());
		this.age = requestInfo.getIntParameter(ApiUrlParamEnum.age.getParamName(), 0);
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		this.id = requestInfo.getIntParameter(ApiUrlParamEnum.id.getParamName(), 0);
		this.realName = requestInfo.getParameter(ApiUrlParamEnum.realName.getParamName(), "");
		//TODO 0:添加默认联系人，1:手动添加联系人 
		this.type = requestInfo.getIntParameter(ApiUrlParamEnum.type.getParamName(), 1);
		if (!StringUtil.isEmpty(phone) && !StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("手机号码有误");
		}
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		if (userId < 1) {
			throw new RequestIllegalException("用户id有误");
		}
		this.openPlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.openPlatformId.getParamName(), OpenPlatformEnum.WECHAT_HDC.getId());
	}

	public String getRelatives() {
		return relatives;
	}

	public void setRelatives(String relatives) {
		this.relatives = relatives;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getOpenPlatformId() {
		return openPlatformId;
	}

	public void setOpenPlatformId(Integer openPlatformId) {
		this.openPlatformId = openPlatformId;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

}
